package com.yst.sqlbuilder;

import com.yst.lambda.TableFieldFunc;

import java.io.Serializable;

public class SQLValue<T> implements Serializable {
    private final TableFieldFunc<T,?> field;
    public TableFieldFunc<T,?> getField(){
        return field;
    }

    private Object oldValue;
    public Object getOldValue(){
        return oldValue;
    }
    private Object value;
    public Object getValue(){
        return value;
    }

    private boolean forceUpdateNull=false;

    /**
     * configure, if value is null,force update null to value
     * @return
     */
    public boolean getForceUpdateNull(){
        return forceUpdateNull;
    }
    public SQLValue<T> setForceUpdateNull(boolean forceUpdateNull){
        this.forceUpdateNull=forceUpdateNull;
        return this;
    }

    public SQLValue(TableFieldFunc<T,?> field,Object value){
        this.field=field;
        this.value=value;
    }

    public SQLValue(TableFieldFunc<T,?> field){
        this(field,null);
    }

    public SQLValue<T> setValue(Object value){
        this.oldValue=this.value;
        this.value=value;
        return this;
    }

    public static <T> SQLValue<T> of(TableFieldFunc<T,?> field,Object value){
        return new SQLValue<T>(field,value);
    }

}
